package com.sky.controller.admin;

import com.sky.mapper.UserMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.RegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/admin/user")
@Api(tags = "用户相关接口")
public class UserController {
    @Autowired
    private RegisterService registerService;
    @Autowired
    private UserMapper userMapper;
    @ApiOperation("获取未审核注册")
    @GetMapping("/getNoAudit/{page}/{size}")
    public Result<PageResult> getNoAudit(@PathVariable Integer page, @PathVariable Integer size){
        return Result.success(registerService.getNoAudit(page,size));
    }
    @ApiOperation("获取未通过注册")
    @GetMapping("/getNoPass/{page}/{size}")
    public Result<PageResult> getNoPass(@PathVariable Integer page,@PathVariable Integer size){
        return Result.success(registerService.getNoPass(page,size));
    }
    @ApiOperation("获取已注册员工")
    @GetMapping("/getRegistered/{page}/{size}")
    public Result<PageResult> getRegistered(@PathVariable Integer page,@PathVariable Integer size){
        return Result.success(registerService.getRegistered(page,size));
    }
    @ApiOperation("删除未通过注册")
    @DeleteMapping("/deleteNoPass/{id}")
    public Result deleteNoPass(@PathVariable Integer id){
        registerService.deleteNoPassById(id);
        return Result.success();
    }

    @ApiOperation("冻结解冻")
    @PutMapping("/stopOrStart/{id}/{status}")
    public Result stopOrStart(@PathVariable Integer id,@PathVariable Integer status){
        userMapper.updateStatus(id,status);
        return Result.success();
    }

    @ApiOperation("删除账号")
    @DeleteMapping("/deleteRegistered/{id}")
    public Result deleteRegistered(@PathVariable Integer id){
        userMapper.deleteNoPassById(id);
        return Result.success();
    }
    @ApiOperation("拒绝注册")
    @PutMapping("/rejectRegister/{id}")
    public Result rejectRegister(@PathVariable Integer id){
        registerService.rejectRegister(id);
        return Result.success();
    }

    @ApiOperation("同意注册")
    @PutMapping("/acceptRegister/{id}")
    public Result acceptRegister(@PathVariable Integer id){
        registerService.acceptRegister(id);
        return Result.success();
    }

}
